/*
 * config.h
 *
 *  Created on: 2011-4-27
 *      Author: chenl
 */

#ifndef CONFIG_H_
#define CONFIG_H_

#include "tinyxml.h"
#include "loki/Singleton.h"
#include "logengine/simplelog.h"

#define CONFIG_FILE "./config/config.xml"

enum
{
	enmScheduler_O_N = 1,	//linux 2.4 O(n) scheduler
	enmScheduler_O_1 = 2,	//linux 2.6 O(1) scheduler
	enmScheduler_BFS = 3,	//Brain Fuck Scheduler
	enmScheduler_CFS = 4,   //Completely Fair Scheduler
};

struct LogConf
{
	LogLevel logLevel;
	uint32_t maxLogFileSize;
};

struct SysConf
{
	int32_t nMaxTask;
	int32_t HZ;
};

struct PSConf
{
	int32_t scheduler;
	int32_t slowerTimes;
};

class CParamConfig
{
public:
	CParamConfig();
	~CParamConfig(){}

	int32_t Initialize();
	int32_t Uninitialize()
	{
		return S_OK;
	}
	int32_t Reload();

public:
	LogLevel GetLogLevel() const
	{
		return logconf_.logLevel;
	}

	void SetLogLevel(LogLevel logLevel)
	{
		logconf_.logLevel = logLevel;
	}

	uint32_t GetMaxLogFileSize() const
	{
		return logconf_.maxLogFileSize;
	}

	void SetMaxLogFileSize(uint32_t maxLogFileSize)
	{
		logconf_.maxLogFileSize = maxLogFileSize;
	}

	int32_t GetMaxTask() const
	{
		return sysconf_.nMaxTask;
	}

	void SetMaxTask(int32_t maxTask)
	{
		sysconf_.nMaxTask = maxTask;
	}

	int32_t GetHZ() const
	{
		return sysconf_.HZ;
	}

	void SetHZ(int32_t hz)
	{
		sysconf_.HZ = hz;
	}

	int32_t GetScheduler() const
	{
		return psconf_.scheduler;
	}

	void SetScheduler(int32_t scheduler)
	{
		psconf_.scheduler = scheduler;
	}

	int32_t GetSlowerTimes() const
	{
		return psconf_.slowerTimes;
	}

	void SetSloerTimes(int32_t slowerTimes)
	{
		psconf_.slowerTimes = slowerTimes;
	}

private:
	int32_t _LoadLogConf(TiXmlElement* pLogConf);
	int32_t _LoadSysConf(TiXmlElement* pSysConf);
	int32_t _LoadPSConf(TiXmlElement* pPSConf);

public:
	CSimpleLog logEngine;

private:
	LogConf	logconf_;
	SysConf sysconf_;
	PSConf	psconf_;
	bool	bReload_;
};

typedef Loki::SingletonHolder<CParamConfig> ParamConfig;

#define CREATE_PARAMCONFIG_INSTANCE		ParamConfig::Instance
#define GET_PARAMCONFIG_INSTANCE		ParamConfig::Instance

#endif /* CONFIG_H_ */
